import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { RouterModule, Routes } from '@angular/router';  /*引入路由*/

// 所有路由的组件都需要引入
import { TodayComponent } from './today/today.component';
import { WeatherComponent } from './weather/weather.component';
import { ConstellationComponent } from './constellation/constellation.component';
import { StoryComponent } from './story/story.component';


// 配置路由
const routes: Routes = [
  {
    path: 'today',
    component: TodayComponent
  },
  {
    path: 'weather',
    component: WeatherComponent
  },
  {
    path: 'constellation',
    component: ConstellationComponent
  },
  {
    path: 'story',
    component: StoryComponent
  },
  {     /*刚进来是空路由就跳转到默认路由*/
    path: '',
    redirectTo: 'today',
    pathMatch: 'full'
  },
  {     /*匹配不到任意路由的话也跳转到默认路由*/
    path: '**',
    redirectTo: 'today',
    // component: TodayComponent   这种方式也可以，不过上面可以修改不符合的路由地址
  }
];


@NgModule({
  imports: [
    CommonModule,
    RouterModule.forRoot(routes)   /*初始化路由器*/
  ],
  declarations: [],
  exports: [
    RouterModule    /*暴露路由模块*/
  ]
})
export class AppRoutingModule { }
